# coding=utf-8

import pika

# 首先应该创建一个连接并打开一个 Channel
connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost'))
channel = connection.channel()

# 不声明 Exchange，使用默认的 Exchange

# 声明名为 hello 的 queue
channel.queue_declare(queue='hello')

print ' [*] Waiting for messages. To exit press CTRL+C'

# 定义回调函数
def callback(ch, method, properties, body):
    print " [x] Received %r" % (body,)

# 订阅消息
channel.basic_consume(callback,
                      queue='hello',
                      no_ack=True)

# 循环等待消息到达
channel.start_consuming()
